<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['hdps']=$basic['hdps'];
if($_RQ['op']=='main'){
	$mystoreid=pdo_getcolumn('jy_yiliao_user',array('mid'=>$_SESSION['uid']),'storeid');
	if($mystoreid){
		$return['store']=pdo_get('jy_yiliao_store',array('id'=>$mystoreid));
	}
	$return['province']=file_get_contents('core/resource/area.txt');
	$return['province']=unserialize($return['province']);
	$return['pcd']=array(
		'province' =>trim($_RQ['province']),
		'city' =>trim($_RQ['city']),
		'district' =>trim($_RQ['district']),
	);
	set_html('title','医生列表');
	$return['sharedata']=array(
		'title'=>'医生列表'.$basic['share_title'],
		'desc'=>'医生列表'.$basic['share_desc'],
		'link'=>custom_url('jy_yiliao/worker_list/',true),
		'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	$return['labels']=pdo_getall('jy_yiliao_label',array('uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
	$return['params']=array(
		'labelid' =>intval($_RQ['labelid']),
		'order'=>$_RQ['order']
	);
	if($_RQ['keyword']){
		$return['params']['keyword']=$_RQ['keyword'];
	}
	exi($return);
}
if($_RQ['op']=='getlist'){
	$post=get_postdata();
	$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
	$type=intval($_RQ['type']);
	//$worker_ids=pdo_getall('jy_yiliao_lesson_log',array('mid'=>$_SESSION['uid'],'worker_id'=>0),'worker_id','worker_id');
	//if($worker_ids){
	//	$worker_ids=array_keys($worker_ids);
	//}
	//if($worker_ids){
	//	$params['id']=$worker_ids;
	//}
	if($_RQ['labelid']){
		$params['label like']='%;'.trim($_RQ['labelid']).';%';
	}
	if($_RQ['order']=='tomday'){
		$dayweekid=date("w",time());
		$params['on_days like']='%;'.$dayweekid.';%';
	}
	if($_RQ['order']=='tomday2'){
		$minweekid=date("w",time()+24*3600);
		$params['on_days like']='%;'.$minweekid.';%';
	}
	if($_RQ['keyword']){
		$label=pdo_get('jy_yiliao_label',array('title like'=>'%'.trim($_RQ['keyword']).'%','uniacid'=>$_SESSION['uniacid']),array('title','id'),'id');
		if($label['id']){
			$params['label like']='%;'.$label['id'].';%';
		}else{
			$params['name like']='%'.trim($_RQ['keyword']).'%';
		}
	}
	if($_RQ['storeid']){
		$params['storeid']=intval($_RQ['storeid']);
	}else{
		if($_RQ['area_id']){
			$storeids=pdo_getall('jy_yiliao_store',array('area_id'=>$_RQ['area_id']),'id','id');
			if($storeids){
				$storeids=array_keys($storeids);
				$params['storeid']=$storeids;
			}else{
				$params['storeid']=0;
			}
		}
	}
	//排序医生
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$return['status']=0;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'fields'=>$fields,
		'orderby'=>$orderby,
	);
	$list=pdo_getslice('jy_yiliao_worker',$params,array($pindex,$psize),$total,$fields,'','id desc');
	$sum=0;
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$label=str_array($item['label']);
			$item['label']=array();
			foreach($label as $lv){
				$getlabel=pdo_get('jy_yiliao_label',array('id'=>$lv,'uniacid'=>$_SESSION['uniacid']));
				if($getlabel){
					$item['label'][]=$getlabel;
				}
			}
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['lessontitle']=pdo_getcolumn('jy_yiliao_lesson',array('id'=>$item['lesson_id']),'title');
			$item['storetitle']=pdo_getcolumn('jy_yiliao_store',array('id'=>$item['storeid']),'title');
			$item['downnum']=pdo_count('jy_yiliao_lesson_log',array('worker_id'=>$item['id']),'id');
			$item['allnum']=pdo_count('jy_yiliao_lesson_log',array('worker_id'=>$item['id']),'id');
		}
	}
	$return['list']=$list;
	$return['sum']=$sum;
	set_html('title','医生列表');
	$return['sharedata']=array(
		'title'=>'医生列表'.$basic['share_title'],
		'desc'=>'医生列表'.$basic['share_desc'],
		'link'=>custom_url('jy_yiliao/worker_list/',true),
		'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		$all=pdo_getall('jy_yiliao_worker',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'','','id desc');
		$id=$all[0]['id'];
	}
	$return['item']=pdo_get('jy_yiliao_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	$return['item']['lesson_group']=$this->get('lesson_group',array('id'=>$return['item']['lesson_groupid']));
	if($return['item']['storeid']){
		$return['item']['store']=$this->get('store',array('id'=>$return['item']['storeid']));
		$return['item']['store']['pcd']=json_decode($return['item']['store']['pcd'],true);
	}
	$return['item']['statustitle']=$this->order_status[$return['item']['status']];
	$return['item']['createtime']=date('Y-m-d H:i:s',$return['item']['createtime']);
	set_html('title','医生详情');
	exi($return);
}
	
